﻿#ifndef _CQUERY_FILTER_H_
#define _CQUERY_FILTER_H_

#include "udatabase/dll_cfg.h"
#include "udatabase/interface/iqueryfilter.h"
#include "geometry/interface/igeometry.h"
//#include "jas-XGeometry/geometryfactory.h"
#include "geometry/geometryfactory.h"

namespace FD
{
	namespace Utility
	{
		namespace DB
		{
			/// <summary>
			/// 查询类
			/// 构造查询对象
			/// </summary>
			class FD_DB_Export CQueryFilter : public FD::Utility::DB::Interface::IQueryFilter
			{
			public:
				///<summary>
				///构造函数
				///</summary>
				CQueryFilter();
				/*CQueryFilter(CQueryFilter & filter);*/
				///<summary>
				///析构函数
				///</summary>
				virtual ~CQueryFilter();
			public:
				///<summary>
				///获取字段名
				///</summary>
				///<param name=""></param>
				///<returns>字段名</returns>
				virtual String getFieldName() const;
				///<summary>
				///获取查询条件
				///</summary>
				///<param name=""></param>
				///<returns>查询条件</returns>
				virtual String getWhereClause() const;
				///<summary>
				///获取查询结果的行数
				///</summary>
				///<param name=""></param>
				///<returns>行数</returns>
				virtual UINT32 getLimitNum() const;
				/// <summary>
				/// 获取需要跳过的行数
				/// </summary>
				/// <param name=""></param>
				/// <returns>跳过的行数</returns>
				virtual UINT32 getOffsetNum() const;
				///<summary>
				///设置字段名
				///</summary>
				///<param name="names">字段名</param>
				///<returns></returns>
				virtual void setFieldName(const String& names);
				///<summary>
				///设置查询条件
				///</summary>
				///<param name="whereclause">查询条件</param>
				///<returns></returns>
				virtual void setWhereClause(const String& whereclause);
				///<summary>
				///设置查询结果的行数
				///</summary>
				///<param name="limit">行数</param>
				///<returns></returns>
				virtual void setLimitNum(UINT32 limit);
				/// <summary>
				/// 设置需要跳过的行数
				/// </summary>
				/// <param name="offset">跳过的行数</param>
				/// <returns></returns>
				virtual void setOffsetNum(UINT32 offset);
				///<summary>
				///克隆
				///</summary>
				///<param name=""></param>
				///<returns>查询器</returns>
				virtual FD::Utility::DB::Interface::IQueryFilter * clone() const;

				/*************************************************************
				*  \描述：获取/设置 空间查询对象
				*  \参数：[void]
				*  \返回：空间查询对象
				*  \备注: 
				***************************************************************/
				const FD::Kernel::Geometry::Interface::IGeometry* getQueryGeometryRef() const;
				void setQueryGeometry(const FD::Kernel::Geometry::Interface::IGeometry* geometry);

				/*************************************************************
				*  \描述：设置/获取空间查询关系
				*  \参数：[void]
				*  \返回：[void] 
				*  \备注: 
				***************************************************************/
				void setSpatialRelation(FD::Utility::DB::Interface::SpatialQueryRelationType spatialRelType);
				FD::Utility::DB::Interface::SpatialQueryRelationType getSpatialRelation();

				/*************************************************************
				*  \描述：设置/获取查询模式
				*  \参数：[void]
				*  \返回：[void] 
				*  \备注: 
				***************************************************************/
				void setQueryMode(FD::Utility::DB::Interface::QueryModeType queryMode);
				FD::Utility::DB::Interface::QueryModeType getQueryMode() const;
				///<summary>
				///将私有成员的相关值存到流中
				///</summary>
				///<param name="stream">流</param>
				///<returns></returns>
				void toBinary(FD::Kernel::DataStream &stream);
				void fromBinary(FD::Kernel::DataStream &stream);

			private:
				/* SQL语句的字段 */
				String m_szFields;
				/* SQL语句的WhereClause语句 */
				String m_szWhereClause;
				/* 空间查询对象 */
				FD::Kernel::Geometry::Interface::IGeometry* m_pQueryGeometry;
				/* 空间查询关系 */
				FD::Utility::DB::Interface::SpatialQueryRelationType m_nSpatialRelation;
				/* 空间查询的九交模型描述 */
				String m_szSpatialRelationString;
				/* 查询模式 */
				FD::Utility::DB::Interface::QueryModeType m_nQueryMode;
				/* 是否先空间查询，默认为false */
				bool m_bIsFirstSpatialQuery;
				/* Buffer大小 */
				double m_dfBuffer;

				INT32 m_limitedNum;
				INT32 m_offsetNum;
			};
		}
	}
} //End of Namespaces
#endif //_CQUERY_FILTER_H_H_

